import random
import string
from datetime import datetime, timedelta

# 模拟30个雷达设备
from time import sleep

from dao.mqttHelp import MQTTClient


def creatData(merged_list):
    all_vehicle_data = []
    # 生成每个雷达设备的车辆数据
    for i in range(len(merged_list)):
        current_time = datetime.now()
        device_data = {
            "location":merged_list[i],
            "device_num":f"xiangyalu{i+1}",
            "timestamp":current_time.strftime("%Y/%m/%d-%H:%M:%S"),
            "longitude":112.53413256,
            "latitude":28.3525675,
            "altitude":50.21,
            "radar_status":random.randint(0, 1),
            "video_status":random.randint(0, 1),
            "cpu_usage":30,
            "memory_usage":21,
            "temperature":45
        }

        all_vehicle_data.append(device_data)
    return all_vehicle_data


nanxian = ["CK0+530", "CK0+410", "CK0+290", "CK0+170", "SK2+132", "SK2+252", "SK2+372", "SK2+492", "SK2+612", "SK2+732",
           "SK2+852", "SK2+972", "SK3+92", "SK3+212", "SK3+332", "SK3+452", "SK3+572", "SK3+692", "SK3+812", "SK3+932",
           "SK4+52", "SK4+172", "SK4+292", "SK4+412", "SK4+532", "SK4+652", "SK4+772", "SK4+892", "SK5+12", "SK5+132",
           "SK5+252", "SK5+372", "EK0+96", "EK0+216"] # 南入口1：CK0+170 南入口2：SK2+132  南出口1：SK5+372  南出口1：EK0+216
beixian = ["GK0+307", "GK0+187", "NK2+130", "NK2+250", "NK2+370", "NK2+490", "NK2+610", "NK2+730", "NK2+850", "NK2+970",
           "NK3+90", "NK3+210", "NK3+330", "NK3+450", "NK3+570", "NK3+690", "NK3+810", "NK3+930", "NK4+50", "NK4+170",
           "NK4+290", "NK4+410", "NK4+530", "NK4+650", "NK4+770", "NK4+890", "NK5+10", "NK5+130", "DK0+74", "DK0+194",
           "DK0+314"]  # 北入口1：GK0+187  北入口2：NK5+10    北出口1：NK2+970   北出口1：DK0+194
merged_list = nanxian + beixian


# 实例化 MQTTClient
mqtt_client = MQTTClient()

for i in range(1):
    # 输出所有雷达设备的数据
    all_vehicle_data=creatData(merged_list)
    print(all_vehicle_data)

    # 发布多个不同参数的消息(暂时用这个)
    mqtt_client.publish_multiple_messages("device_status", all_vehicle_data)
    sleep(30)
    i+=1

# 并发 发布多个不同参数的消息（待测试）
# mqtt_client.publish_multiple_messages_concurrently("objects_list", all_vehicle_data)